﻿namespace HRM.CORE
{
    using DevExpress.Data;
    using DevExpress.Utils;
    using DevExpress.XtraBars;
    using DevExpress.XtraEditors;
    using DevExpress.XtraEditors.Controls;
    using DevExpress.XtraEditors.Repository;
    using DevExpress.XtraGrid;
    using DevExpress.XtraGrid.Columns;
    using DevExpress.XtraGrid.Views.Grid;
    using APP.HELPER;
    using Common.Class; using APP.HELPER.Utils.Language; using Security.Security; using Dictionary.ERP;
    using HRM.CORE;
    using HRM.CORE.REPORT;
    
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;
    using Common;
    using Security.ERP;
    using DevExpress.XtraGrid.Views.Base;

    public class xucContract : Common.xucBase
    {
        private Bar bar1;
        private Bar bar2;
        private BarDockControl barDockControlBottom;
        private BarDockControl barDockControlLeft;
        private BarDockControl barDockControlRight;
        private BarDockControl barDockControlTop;
        private BarManager barManager1;
        private BarButtonItem bbiAdd;
        private BarButtonItem bbiClose;
        private BarButtonItem bbiDelete;
        private BarButtonItem bbiEdit;
        private BarButtonItem bbiExport;
        private BarEditItem bbiFilter;
        private BarButtonItem bbiPrint;
        private BarButtonItem bbiReload;
        private BarButtonItem bbiView;
        private GridColumn colBranchName;
        private GridColumn colContractCode;
        private GridColumn colContractTime;
        private GridColumn colContractType;
        private GridColumn colContractTypeString;
        private GridColumn colDepartmentName;
        private GridColumn colDescription;
        private GridColumn colEmployeeCode;
        private GridColumn colFirstName;
        private GridColumn colFromDate;
        private GridColumn colGroupName;
        private GridColumn colLastName;
        private GridColumn colSignDate;
        private GridColumn colSigner;
        private GridColumn colSignerPosition;
        private GridColumn colSubject;
        private GridColumn colToDate;
        private IContainer components = null;
        private GridView gbList;
        private GridControl gcList;
        public DevExpress.Utils.ImageCollection imageCollection2;
        private string m_Code = MyLogin.Code;
        private string m_EmployeeCode = "";
        private string m_Filter = "0";
        private int m_Level = MyLogin.Level;
        private PopupMenu popupMenu1;
        private RepositoryItemImageComboBox repFilter;
        private SplitContainerControl splitContainerControl1;
        private xucListContractEmployee xucListContractEmployee1;

        public event ClosedHander Closed;

        public xucContract()
        {
            this.InitializeComponent();
            base.RestoreLayout(this.gbList, this);
            this.InitMultiLanguages();
            this.LoadOrganization();
            this.Init();
            this.barManager1.SetPopupContextMenu(this.gcList, this.popupMenu1);
            this.splitContainerControl1.SplitterPosition = LoadStyle();
        }

        private void Add()
        {
            xfmContractAdd add = new xfmContractAdd(Actions.Add);
            add.Added += new xfmContractAdd.AddedEventHander(this.frm_Added);
            add.ShowDialog();
        }

        private void bbiAdd_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Add();
        }

        private void bbiClose_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.RaiseClosedHander();
        }

        private void bbiDelete_ItemClick(object sender, ItemClickEventArgs e)
        {
            if (MyRule.IsDelete("bbiContract"))
            {
                bool flag = false;
                int[] selectedRows = this.gbList.GetSelectedRows();
                if (XtraMessageBox.Show("Bạn c\x00f3 muốn x\x00f3a kh\x00f4ng?", "Th\x00f4ng b\x00e1o", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.No)
                {
                    string str;
                    object rowCellValue;
                    HRM_EMPLOYEE hrm_employee;
                    base.SetWaitDialogCaption("Đang x\x00f3a...");
                    HRM_CONTRACT hrm_contract = new HRM_CONTRACT();
                    for (int i = selectedRows.Length; i > 0; i--)
                    {
                        flag = true;
                        rowCellValue = this.gbList.GetRowCellValue(selectedRows[i - 1], "ContractCode");
                        this.m_EmployeeCode = this.gbList.GetRowCellValue(selectedRows[i - 1], "EmployeeCode").ToString();
                        if (rowCellValue != null)
                        {
                            SYS_LOG.Insert("Hợp Đồng Lao Động", "Xo\x00e1", rowCellValue.ToString());
                            str = hrm_contract.Delete(rowCellValue.ToString());
                            if (str == "OK")
                            {
                                this.gbList.DeleteRow(selectedRows[i - 1]);
                                hrm_employee = new HRM_EMPLOYEE();
                                hrm_employee.Get(this.m_EmployeeCode);
                                if (hrm_employee.ContractCode == rowCellValue.ToString())
                                {
                                    hrm_employee.ContractCode = "";
                                    hrm_employee.ContractType = "";
                                    hrm_employee.Update();
                                }
                            }
                            else if (str != "OK")
                            {
                                MessageBox.Show("Th\x00f4ng tin kh\x00f4ng được x\x00f3a" + str, "Th\x00f4ng b\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            }
                        }
                    }
                    this.DoHide();
                    if (!flag && (hrm_contract.GetList(this.m_Level, this.m_Code).Rows.Count != 0))
                    {
                        rowCellValue = this.gbList.GetFocusedRowCellValue("ContractCode");
                        this.m_EmployeeCode = this.gbList.GetFocusedRowCellValue("EmployeeCode").ToString();
                        if (rowCellValue != null)
                        {
                            SYS_LOG.Insert("Hợp Đồng Lao Động", "Xo\x00e1", rowCellValue.ToString());
                            base.SetWaitDialogCaption("Đang x\x00f3a...");
                            str = hrm_contract.Delete(rowCellValue.ToString());
                            if (str == "OK")
                            {
                                this.gbList.DeleteRow(this.gbList.FocusedRowHandle);
                                hrm_employee = new HRM_EMPLOYEE();
                                hrm_employee.Get(this.m_EmployeeCode);
                                if (hrm_employee.ContractCode == rowCellValue.ToString())
                                {
                                    hrm_employee.ContractCode = "";
                                    hrm_employee.ContractType = "";
                                    hrm_employee.Update();
                                }
                            }
                            else if (str != "OK")
                            {
                                MessageBox.Show("Th\x00f4ng tin kh\x00f4ng được x\x00f3a" + str, "Th\x00f4ng b\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            }
                            this.DoHide();
                        }
                    }
                }
            }
        }

        private void bbiEdit_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Change();
        }

        private void bbiExport_ItemClick(object sender, ItemClickEventArgs e)
        {
            base._exportView = this.gbList;
            SYS_LOG.Insert("Hợp Đồng Lao Động", "Xuất");
            base.Export();
        }

        private void bbiPrint_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                new xfmOptionPrintContract(this.m_Level, this.m_Code, this.gbList.GetFocusedRowCellValue(this.colContractCode).ToString(), this.gbList.GetFocusedRowCellValue(this.colEmployeeCode).ToString()).ShowDialog();
            }
            catch
            {
                new xfmOptionPrintContract(this.m_Level, this.m_Code).ShowDialog();
            }
        }

        private void bbiReload_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Init();
        }

        private void Change()
        {
            HRM_CONTRACT item = new HRM_CONTRACT();
            object focusedRowCellValue = this.gbList.GetFocusedRowCellValue("ContractCode");
            if (focusedRowCellValue != null)
            {
                base.SetWaitDialogCaption("Đang kiểm tra dữ liệu....");
                if (item.Get(focusedRowCellValue.ToString()) != "OK")
                {
                    this.DoHide();
                    XtraMessageBox.Show("Dữ liệu kh\x00f4ng tồn tại", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    this.DoHide();
                    xfmContractAdd add = new xfmContractAdd(Actions.Update, item);
                    add.Updated += new xfmContractAdd.UpdatedEventHander(this.frm_Updated);
                    add.Added += new xfmContractAdd.AddedEventHander(this.frm_Added);
                    add.ShowDialog();
                }
            }
        }

        private void Delete()
        {
        }

        public void DisableMenu(bool disable)
        {
            this.bbiEdit.Enabled = !disable;
            this.bbiDelete.Enabled = !disable;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void frm_Added(object sender, HRM_CONTRACT Item)
        {
            this.Init();
        }

        private void frm_Updated(object sender, HRM_CONTRACT Item)
        {
            this.UpdateRow(Item);
        }

        private void gbList_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
        {
            if (e.RowHandle == -2147483648)
            {
                e.Handled = true;
                e.Painter.DrawObject(e.Info);
                Rectangle bounds = e.Bounds;
                e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(0x3f, 0xa5, 0xa5, 0)), bounds);
                bounds.Height--;
                bounds.Width--;
                e.Graphics.DrawRectangle(Pens.Blue, bounds);
            }
            int rowHandle = e.RowHandle;
            if (rowHandle >= 0)
            {
                rowHandle++;
                e.Info.DisplayText = rowHandle.ToString();
            }
        }

        private void gbList_DoubleClick(object sender, EventArgs e)
        {
            if (this.gbList.RowCount != 0)
            {
                this.Change();
            }
        }

        private void gbList_KeyDown(object sender, KeyEventArgs e)
        {
            this.ucList_ListKeyDown(sender, e);
            if ((e.KeyCode == Keys.Delete) && (this.gbList.RowCount != 0))
            {
                this.Delete();
                this.SetMenu(null);
            }
        }

        private void gbList_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                base.DoShowMenu(this.gbList.CalcHitInfo(new Point(e.X, e.Y)), this.gbList, this);
            }
            this.SetMenu(null);
        }

        private void gbList_RowCellClick(object sender, RowCellClickEventArgs e)
        {
        }

        private void gcList_Click(object sender, EventArgs e)
        {
        }

        private void Init()
        {
            this.repFilter.EditValueChanging += new ChangingEventHandler(this.repFilter_EditValueChanging);
            this.repFilter.EditValueChanged += new EventHandler(this.repFilter_EditValueChanged);
            this.LoadGrid(this.m_Level, this.m_Code);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xucContract));
            StyleFormatCondition condition = new StyleFormatCondition();
            StyleFormatCondition condition2 = new StyleFormatCondition();
            this.imageCollection2 = new DevExpress.Utils.ImageCollection(this.components);
            this.bar2 = new Bar();
            this.barManager1 = new BarManager(this.components);
            this.bar1 = new Bar();
            this.bbiFilter = new BarEditItem();
            this.repFilter = new RepositoryItemImageComboBox();
            this.bbiView = new BarButtonItem();
            this.bbiAdd = new BarButtonItem();
            this.bbiEdit = new BarButtonItem();
            this.bbiDelete = new BarButtonItem();
            this.bbiReload = new BarButtonItem();
            this.bbiPrint = new BarButtonItem();
            this.bbiExport = new BarButtonItem();
            this.bbiClose = new BarButtonItem();
            this.barDockControlTop = new BarDockControl();
            this.barDockControlBottom = new BarDockControl();
            this.barDockControlLeft = new BarDockControl();
            this.barDockControlRight = new BarDockControl();
            this.gcList = new GridControl();
            this.gbList = new GridView();
            this.colBranchName = new GridColumn();
            this.colDepartmentName = new GridColumn();
            this.colGroupName = new GridColumn();
            this.colContractCode = new GridColumn();
            this.colEmployeeCode = new GridColumn();
            this.colFirstName = new GridColumn();
            this.colLastName = new GridColumn();
            this.colContractType = new GridColumn();
            this.colContractTypeString = new GridColumn();
            this.colContractTime = new GridColumn();
            this.colSignDate = new GridColumn();
            this.colFromDate = new GridColumn();
            this.colToDate = new GridColumn();
            this.colSigner = new GridColumn();
            this.colSignerPosition = new GridColumn();
            this.colSubject = new GridColumn();
            this.colDescription = new GridColumn();
            this.splitContainerControl1 = new SplitContainerControl();
            this.xucListContractEmployee1 = new xucListContractEmployee();
            this.popupMenu1 = new PopupMenu(this.components);
            this.imageCollection2.BeginInit();
            this.barManager1.BeginInit();
            this.repFilter.BeginInit();
            this.gcList.BeginInit();
            this.gbList.BeginInit();
            this.splitContainerControl1.BeginInit();
            this.splitContainerControl1.SuspendLayout();
            this.popupMenu1.BeginInit();
            base.SuspendLayout();
//            this.imageCollection2.ImageStream = (ImageCollectionStreamer) manager.GetObject("imageCollection2.ImageStream");
            this.imageCollection2.Images.SetKeyName(0x3d, "Vista (35).ico");
            this.imageCollection2.Images.SetKeyName(0x3e, "Security.ico");
            this.imageCollection2.Images.SetKeyName(0x3f, "RibbonPrintPreview_DocumentMapLarge.png");
            this.imageCollection2.Images.SetKeyName(0x40, "11.png");
            this.imageCollection2.Images.SetKeyName(0x41, "Sua.png");
            this.imageCollection2.Images.SetKeyName(0x42, "Them.png");
            this.imageCollection2.Images.SetKeyName(0x43, "PhanQuyen.png");
            this.imageCollection2.Images.SetKeyName(0x44, "11.png");
            this.imageCollection2.Images.SetKeyName(0x45, "plus.png");
            this.bar2.BarName = "Tools";
            this.bar2.DockCol = 0;
            this.bar2.DockRow = 0;
            this.bar2.DockStyle = BarDockStyle.Top;
            this.bar2.OptionsBar.AllowQuickCustomization = false;
            this.bar2.OptionsBar.DrawDragBorder = false;
            this.bar2.OptionsBar.UseWholeRow = true;
            this.bar2.Text = "Tools";
            this.barManager1.Bars.AddRange(new Bar[] { this.bar1 });
            this.barManager1.DockControls.Add(this.barDockControlTop);
            this.barManager1.DockControls.Add(this.barDockControlBottom);
            this.barManager1.DockControls.Add(this.barDockControlLeft);
            this.barManager1.DockControls.Add(this.barDockControlRight);
            this.barManager1.Form = this;
            this.barManager1.Images = this.imageCollection2;
            this.barManager1.Items.AddRange(new BarItem[] { this.bbiAdd, this.bbiView, this.bbiPrint, this.bbiEdit, this.bbiClose, this.bbiFilter, this.bbiDelete, this.bbiReload, this.bbiExport });
            this.barManager1.MaxItemId = 10;
            this.barManager1.RepositoryItems.AddRange(new RepositoryItem[] { this.repFilter });
            this.bar1.BarName = "Tools";
            this.bar1.DockCol = 0;
            this.bar1.DockRow = 0;
            this.bar1.DockStyle = BarDockStyle.Top;
            this.bar1.FloatLocation = new Point(0x47, 0x86);
            this.bar1.LinksPersistInfo.AddRange(new LinkPersistInfo[] { new LinkPersistInfo(BarLinkUserDefines.Width | BarLinkUserDefines.PaintStyle, this.bbiFilter, "", true, true, true, 0x12d, null, BarItemPaintStyle.CaptionGlyph), new LinkPersistInfo(this.bbiView), new LinkPersistInfo(BarLinkUserDefines.PaintStyle, this.bbiAdd, "", true, true, true, 0, null, BarItemPaintStyle.CaptionGlyph), new LinkPersistInfo(BarLinkUserDefines.PaintStyle, this.bbiEdit, BarItemPaintStyle.CaptionGlyph), new LinkPersistInfo(BarLinkUserDefines.PaintStyle, this.bbiDelete, BarItemPaintStyle.CaptionGlyph), new LinkPersistInfo(BarLinkUserDefines.PaintStyle, this.bbiReload, BarItemPaintStyle.CaptionGlyph), new LinkPersistInfo(BarLinkUserDefines.PaintStyle, this.bbiPrint, BarItemPaintStyle.CaptionGlyph), new LinkPersistInfo(BarLinkUserDefines.PaintStyle, this.bbiExport, BarItemPaintStyle.CaptionGlyph), new LinkPersistInfo(BarLinkUserDefines.PaintStyle, this.bbiClose, BarItemPaintStyle.CaptionGlyph) });
            this.bar1.OptionsBar.UseWholeRow = true;
            this.bar1.Text = "Tools";
            this.bbiFilter.Caption = "Lọc dữ liệu theo:";
            this.bbiFilter.Edit = this.repFilter;
            this.bbiFilter.Id = 6;
            this.bbiFilter.Name = "bbiFilter";
            this.bbiFilter.Width = 200;
            this.repFilter.Appearance.Font = new Font("Tahoma", 8.25f, FontStyle.Bold);
            this.repFilter.Appearance.Options.UseFont = true;
            this.repFilter.AutoHeight = false;
            this.repFilter.Buttons.AddRange(new EditorButton[] { new EditorButton(ButtonPredefines.Combo) });
            this.repFilter.Items.AddRange(new ImageComboBoxItem[] { new ImageComboBoxItem("<Tất cả hợp đồng>", 0, -1), new ImageComboBoxItem("<Danh s\x00e1ch HĐLĐ c\x00f2n thời hạn>", 1, -1), new ImageComboBoxItem("<Danh s\x00e1ch HĐLĐ sắp hết hạn>", 2, -1), new ImageComboBoxItem("<Danh s\x00e1ch HĐLĐ đ\x00e3 hết hạn>", 3, -1) });
            this.repFilter.Name = "repFilter";
            this.repFilter.NullText = "<Tất cả hợp đồng>";
            this.bbiView.Caption = "Xem";
            this.bbiView.Id = 2;
            this.bbiView.ImageIndex = 3;
            this.bbiView.Name = "bbiView";
            this.bbiAdd.Caption = "Th\x00eam";
            this.bbiAdd.Id = 1;
            this.bbiAdd.ImageIndex = 0x45;
            this.bbiAdd.Name = "bbiAdd";
            this.bbiAdd.ItemClick += new ItemClickEventHandler(this.bbiAdd_ItemClick);
            this.bbiEdit.Caption = "Sửa";
            this.bbiEdit.Id = 4;
            this.bbiEdit.ImageIndex = 14;
            this.bbiEdit.Name = "bbiEdit";
            this.bbiEdit.ItemClick += new ItemClickEventHandler(this.bbiEdit_ItemClick);
            this.bbiDelete.Caption = "X\x00f3a";
            this.bbiDelete.Id = 7;
            this.bbiDelete.ImageIndex = 13;
            this.bbiDelete.Name = "bbiDelete";
            this.bbiDelete.ItemClick += new ItemClickEventHandler(this.bbiDelete_ItemClick);
            this.bbiReload.Caption = "Nạp Lại";
            this.bbiReload.Id = 8;
            this.bbiReload.ImageIndex = 0x2a;
            this.bbiReload.Name = "bbiReload";
            this.bbiReload.ItemClick += new ItemClickEventHandler(this.bbiReload_ItemClick);
            this.bbiPrint.Caption = "In";
            this.bbiPrint.Id = 3;
            this.bbiPrint.ImageIndex = 9;
            this.bbiPrint.Name = "bbiPrint";
            this.bbiPrint.ItemClick += new ItemClickEventHandler(this.bbiPrint_ItemClick);
            this.bbiExport.Caption = "Xuất";
            this.bbiExport.Id = 9;
            this.bbiExport.ImageIndex = 0x31;
            this.bbiExport.Name = "bbiExport";
            this.bbiExport.ItemClick += new ItemClickEventHandler(this.bbiExport_ItemClick);
            this.bbiClose.Caption = "Đ\x00f3ng";
            this.bbiClose.Id = 5;
            this.bbiClose.ImageIndex = 0x16;
            this.bbiClose.Name = "bbiClose";
            this.bbiClose.ItemClick += new ItemClickEventHandler(this.bbiClose_ItemClick);
            this.gcList.Dock = DockStyle.Fill;
            this.gcList.EmbeddedNavigator.Buttons.Append.Visible = false;
            this.gcList.EmbeddedNavigator.Buttons.CancelEdit.Visible = false;
            this.gcList.EmbeddedNavigator.Buttons.Edit.Visible = false;
            this.gcList.EmbeddedNavigator.Buttons.EndEdit.Visible = false;
            this.gcList.EmbeddedNavigator.Buttons.Remove.Visible = false;
            this.gcList.EmbeddedNavigator.TextStringFormat = "{0}/{1}";
            this.gcList.Location = new Point(0, 0);
            this.gcList.MainView = this.gbList;
            this.gcList.Name = "gcList";
            this.gcList.Size = new Size(0x2c1, 0x22f);
            this.gcList.TabIndex = 3;
            this.gcList.UseEmbeddedNavigator = true;
            this.gcList.ViewCollection.AddRange(new BaseView[] { this.gbList });
            this.gcList.DoubleClick += new EventHandler(this.gbList_DoubleClick);
            this.gcList.Click += new EventHandler(this.gcList_Click);
            this.gbList.Appearance.GroupRow.Font = new Font("Tahoma", 8.25f, FontStyle.Bold);
            this.gbList.Appearance.GroupRow.Options.UseFont = true;
            this.gbList.Appearance.HeaderPanel.Options.UseTextOptions = true;
            this.gbList.Appearance.HeaderPanel.TextOptions.WordWrap = WordWrap.Wrap;
            this.gbList.BorderStyle = BorderStyles.NoBorder;
            this.gbList.ColumnPanelRowHeight = 0x20;
            this.gbList.Columns.AddRange(new GridColumn[] { 
                this.colBranchName, this.colDepartmentName, this.colGroupName, this.colContractCode, this.colEmployeeCode, this.colFirstName, this.colLastName, this.colContractType, this.colContractTypeString, this.colContractTime, this.colSignDate, this.colFromDate, this.colToDate, this.colSigner, this.colSignerPosition, this.colSubject, 
                this.colDescription
             });
            this.gbList.FixedLineWidth = 1;
            this.gbList.FocusRectStyle = DrawFocusRectStyle.RowFocus;
            condition.Appearance.ForeColor = Color.Chocolate;
            condition.Appearance.Options.UseForeColor = true;
            condition.ApplyToRow = true;
            condition.Condition = FormatConditionEnum.Expression;
            condition.Expression = " UtcNow()>= AddDays([ToDate],-10 )";
            condition2.Appearance.ForeColor = Color.Red;
            condition2.Appearance.Options.UseForeColor = true;
            condition2.ApplyToRow = true;
            condition2.Condition = FormatConditionEnum.Expression;
            condition2.Expression = "[ToDate]<UtcNow()";
            this.gbList.FormatConditions.AddRange(new StyleFormatCondition[] { condition, condition2 });
            this.gbList.GridControl = this.gcList;
            this.gbList.GroupPanelText = "K\x00e9o v\x00e0 Thả cột v\x00e0o đ\x00e2y để nh\x00f3m dữ liệu";
            this.gbList.IndicatorWidth = 40;
            this.gbList.Name = "gbList";
            this.gbList.OptionsBehavior.AllowIncrementalSearch = true;
            this.gbList.OptionsBehavior.AutoExpandAllGroups = true;
            this.gbList.OptionsBehavior.CopyToClipboardWithColumnHeaders = false;
            this.gbList.OptionsBehavior.FocusLeaveOnTab = true;
            this.gbList.OptionsLayout.StoreAllOptions = true;
            this.gbList.OptionsLayout.StoreAppearance = true;
            this.gbList.OptionsMenu.EnableColumnMenu = false;
            this.gbList.OptionsMenu.EnableGroupPanelMenu = false;
            this.gbList.OptionsNavigation.EnterMoveNextColumn = true;
            this.gbList.OptionsSelection.InvertSelection = true;
            this.gbList.OptionsSelection.MultiSelect = true;
            this.gbList.OptionsView.ColumnAutoWidth = false;
            this.gbList.OptionsView.EnableAppearanceEvenRow = true;
            this.gbList.OptionsView.RowAutoHeight = true;
            this.gbList.OptionsView.ShowAutoFilterRow = true;
            this.gbList.ViewCaption = "MainCaption";
            this.gbList.CustomDrawRowIndicator += new RowIndicatorCustomDrawEventHandler(this.gbList_CustomDrawRowIndicator);
            this.gbList.MouseDown += new MouseEventHandler(this.gbList_MouseDown);
            this.colBranchName.Caption = "Chi nh\x00e1nh";
            this.colBranchName.FieldName = "BranchName";
            this.colBranchName.Name = "colBranchName";
            this.colDepartmentName.Caption = "Ph\x00f2ng ban";
            this.colDepartmentName.FieldName = "DepartmentName";
            this.colDepartmentName.Name = "colDepartmentName";
            this.colGroupName.Caption = "Tổ nh\x00f3m";
            this.colGroupName.FieldName = "GroupName";
            this.colGroupName.Name = "colGroupName";
            this.colContractCode.Caption = "M\x00e3 hợp đồng";
            this.colContractCode.FieldName = "ContractCode";
            this.colContractCode.Fixed = FixedStyle.Left;
            this.colContractCode.Name = "colContractCode";
            this.colContractCode.OptionsColumn.AllowEdit = false;
            this.colContractCode.OptionsColumn.ReadOnly = true;
            this.colContractCode.Visible = true;
            this.colContractCode.VisibleIndex = 0;
            this.colContractCode.Width = 110;
            this.colEmployeeCode.Caption = "M\x00e3 nh\x00e2n vi\x00ean";
            this.colEmployeeCode.FieldName = "EmployeeCode";
            this.colEmployeeCode.Fixed = FixedStyle.Left;
            this.colEmployeeCode.Name = "colEmployeeCode";
            this.colEmployeeCode.OptionsColumn.AllowEdit = false;
            this.colEmployeeCode.OptionsColumn.ReadOnly = true;
            this.colEmployeeCode.Visible = true;
            this.colEmployeeCode.VisibleIndex = 1;
            this.colEmployeeCode.Width = 0x5c;
            this.colFirstName.Caption = "Họ l\x00f3t";
            this.colFirstName.FieldName = "FirstName";
            this.colFirstName.Fixed = FixedStyle.Left;
            this.colFirstName.Name = "colFirstName";
            this.colFirstName.OptionsColumn.AllowEdit = false;
            this.colFirstName.OptionsColumn.ReadOnly = true;
            this.colFirstName.Visible = true;
            this.colFirstName.VisibleIndex = 2;
            this.colFirstName.Width = 0x66;
            this.colLastName.Caption = "T\x00ean";
            this.colLastName.FieldName = "LastName";
            this.colLastName.Fixed = FixedStyle.Left;
            this.colLastName.Name = "colLastName";
            this.colLastName.OptionsColumn.AllowEdit = false;
            this.colLastName.OptionsColumn.ReadOnly = true;
            this.colLastName.Visible = true;
            this.colLastName.VisibleIndex = 3;
            this.colLastName.Width = 0x41;
            this.colContractType.Caption = "Loại hợp đồng";
            this.colContractType.FieldName = "ContractType";
            this.colContractType.Name = "colContractType";
            this.colContractType.OptionsColumn.AllowEdit = false;
            this.colContractType.OptionsColumn.ReadOnly = true;
            this.colContractType.Width = 180;
            this.colContractTypeString.Caption = "Loại hợp đồng";
            this.colContractTypeString.FieldName = "ContractTypeName";
            this.colContractTypeString.Name = "colContractTypeString";
            this.colContractTypeString.OptionsColumn.AllowEdit = false;
            this.colContractTypeString.OptionsColumn.ReadOnly = true;
            this.colContractTypeString.UnboundExpression = "Iif([ContractType] == 0, 'Hợp đồng x\x00e1c định thời hạn' ,Iif([ContractType] == 1, 'Hợp đồng kh\x00f4ng x\x00e1c định thời hạn' ,Iif([ContractType]=2,  'Hợp đồng thử việc', 'Hợp đồng học việc') ) )";
            this.colContractTypeString.UnboundType = UnboundColumnType.String;
            this.colContractTypeString.Visible = true;
            this.colContractTypeString.VisibleIndex = 4;
            this.colContractTypeString.Width = 180;
            this.colContractTime.Caption = "Thời gian";
            this.colContractTime.FieldName = "ContractTime";
            this.colContractTime.Name = "colContractTime";
            this.colContractTime.OptionsColumn.AllowEdit = false;
            this.colContractTime.OptionsColumn.ReadOnly = true;
            this.colContractTime.Visible = true;
            this.colContractTime.VisibleIndex = 5;
            this.colContractTime.Width = 0x4d;
            this.colSignDate.Caption = "Ng\x00e0y k\x00fd";
            this.colSignDate.FieldName = "SignDate";
            this.colSignDate.Name = "colSignDate";
            this.colSignDate.OptionsColumn.AllowEdit = false;
            this.colSignDate.OptionsColumn.ReadOnly = true;
            this.colSignDate.Visible = true;
            this.colSignDate.VisibleIndex = 6;
            this.colFromDate.Caption = "Ng\x00e0y c\x00f3 hiệu lực";
            this.colFromDate.FieldName = "FromDate";
            this.colFromDate.Name = "colFromDate";
            this.colFromDate.OptionsColumn.AllowEdit = false;
            this.colFromDate.OptionsColumn.ReadOnly = true;
            this.colFromDate.Visible = true;
            this.colFromDate.VisibleIndex = 7;
            this.colFromDate.Width = 0x4d;
            this.colToDate.Caption = "Ng\x00e0y hết hiệu lực";
            this.colToDate.FieldName = "ToDate";
            this.colToDate.Name = "colToDate";
            this.colToDate.OptionsColumn.AllowEdit = false;
            this.colToDate.OptionsColumn.ReadOnly = true;
            this.colToDate.Visible = true;
            this.colToDate.VisibleIndex = 8;
            this.colToDate.Width = 0x4d;
            this.colSigner.Caption = "Người k\x00fd";
            this.colSigner.FieldName = "Signer";
            this.colSigner.Name = "colSigner";
            this.colSigner.OptionsColumn.AllowEdit = false;
            this.colSigner.OptionsColumn.ReadOnly = true;
            this.colSigner.Visible = true;
            this.colSigner.VisibleIndex = 9;
            this.colSigner.Width = 0x71;
            this.colSignerPosition.Caption = "Chức vụ người k\x00fd";
            this.colSignerPosition.FieldName = "SignerPosition";
            this.colSignerPosition.Name = "colSignerPosition";
            this.colSignerPosition.OptionsColumn.AllowEdit = false;
            this.colSignerPosition.OptionsColumn.ReadOnly = true;
            this.colSignerPosition.Visible = true;
            this.colSignerPosition.VisibleIndex = 10;
            this.colSignerPosition.Width = 0x75;
            this.colSubject.Caption = "Tr\x00edch yếu";
            this.colSubject.FieldName = "Subject";
            this.colSubject.Name = "colSubject";
            this.colSubject.OptionsColumn.AllowEdit = false;
            this.colSubject.OptionsColumn.ReadOnly = true;
            this.colSubject.Width = 160;
            this.colDescription.Caption = "Ghi ch\x00fa";
            this.colDescription.FieldName = "Description";
            this.colDescription.Name = "colDescription";
            this.colDescription.OptionsColumn.AllowEdit = false;
            this.colDescription.OptionsColumn.ReadOnly = true;
            this.colDescription.Visible = true;
            this.colDescription.VisibleIndex = 11;
            this.colDescription.Width = 220;
            this.splitContainerControl1.Dock = DockStyle.Fill;
            this.splitContainerControl1.Location = new Point(0, 0x1a);
            this.splitContainerControl1.Name = "splitContainerControl1";
//            this.splitContainerControl1.Panel1.Controls.Add(this.xucListContractEmployee1);
            this.splitContainerControl1.Panel1.Text = "Panel1";
            this.splitContainerControl1.Panel2.Controls.Add(this.gcList);
            this.splitContainerControl1.Panel2.Text = "Panel2";
            this.splitContainerControl1.Size = new Size(0x3af, 0x22f);
            this.splitContainerControl1.SplitterPosition = 0xe8;
            this.splitContainerControl1.TabIndex = 4;
            this.splitContainerControl1.Text = "splitContainerControl1";
            this.splitContainerControl1.SplitterPositionChanged += new EventHandler(this.splitContainerControl1_SplitterPositionChanged);
            this.xucListContractEmployee1.Dock = DockStyle.Fill;
            this.xucListContractEmployee1.Location = new Point(0, 0);
            this.xucListContractEmployee1.Name = "xucListContractEmployee1";
            this.xucListContractEmployee1.Size = new Size(0xe8, 0x22f);
            this.xucListContractEmployee1.TabIndex = 0;
            this.popupMenu1.LinksPersistInfo.AddRange(new LinkPersistInfo[] { new LinkPersistInfo(this.bbiAdd), new LinkPersistInfo(this.bbiDelete), new LinkPersistInfo(this.bbiEdit), new LinkPersistInfo(this.bbiPrint), new LinkPersistInfo(this.bbiExport), new LinkPersistInfo(this.bbiReload), new LinkPersistInfo(this.bbiClose), new LinkPersistInfo(this.bbiFilter) });
            this.popupMenu1.Manager = this.barManager1;
            this.popupMenu1.Name = "popupMenu1";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
//            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.splitContainerControl1);
            base.Controls.Add(this.barDockControlLeft);
            base.Controls.Add(this.barDockControlRight);
            base.Controls.Add(this.barDockControlBottom);
            base.Controls.Add(this.barDockControlTop);
            base.Name = "xucContract";
            base.Size = new Size(0x3af, 0x249);
            this.imageCollection2.EndInit();
            this.barManager1.EndInit();
            this.repFilter.EndInit();
            this.gcList.EndInit();
            this.gbList.EndInit();
            this.splitContainerControl1.EndInit();
            this.splitContainerControl1.ResumeLayout(false);
            this.popupMenu1.EndInit();
            base.ResumeLayout(false);
        }

        private void InitMultiLanguages()
        {
            this.bbiFilter.Caption = MultiLanguages.GetString("tbl_Contract", "FilterBy", this.bbiFilter.Caption);
            this.bbiView.Caption = MultiLanguages.GetString("tbl_Contract", "View", this.bbiView.Caption);
            this.bbiEdit.Caption = MultiLanguages.GetString("tbl_Contract", "Edit", this.bbiEdit.Caption);
            this.bbiAdd.Caption = MultiLanguages.GetString("tbl_Contract", "Add", this.bbiAdd.Caption);
            this.bbiDelete.Caption = MultiLanguages.GetString("tbl_Contract", "Delete", this.bbiDelete.Caption);
            this.bbiExport.Caption = MultiLanguages.GetString("tbl_Contract", "Export", this.bbiExport.Caption);
            this.bbiPrint.Caption = MultiLanguages.GetString("tbl_Contract", "Print", this.bbiPrint.Caption);
            this.bbiReload.Caption = MultiLanguages.GetString("tbl_Contract", "Refresh", this.bbiReload.Caption);
            this.bbiClose.Caption = MultiLanguages.GetString("tbl_Contract", "Close", this.bbiClose.Caption);
            this.colContractCode.Caption = MultiLanguages.GetString("tbl_Contract", "ContractCode", this.colContractCode.Caption);
            this.colEmployeeCode.Caption = MultiLanguages.GetString("tbl_Contract", "EmployeeCode", this.colEmployeeCode.Caption);
            this.colFirstName.Caption = MultiLanguages.GetString("tbl_Contract", "FirstName", this.colFirstName.Caption);
            this.colLastName.Caption = MultiLanguages.GetString("tbl_Contract", "LastName", this.colLastName.Caption);
            this.colContractTime.Caption = MultiLanguages.GetString("tbl_Contract", "ContractTime", this.colContractTime.Caption);
            this.colSignDate.Caption = MultiLanguages.GetString("tbl_Contract", "SignDate", this.colSignDate.Caption);
            this.colFromDate.Caption = MultiLanguages.GetString("tbl_Contract", "FromDate", this.colFromDate.Caption);
            this.colToDate.Caption = MultiLanguages.GetString("tbl_Contract", "ToDate", this.colToDate.Caption);
            this.colSigner.Caption = MultiLanguages.GetString("tbl_Contract", "Signer", this.colSigner.Caption);
            this.colSignerPosition.Caption = MultiLanguages.GetString("tbl_Contract", "SignerPosition", this.colSignerPosition.Caption);
            this.colSubject.Caption = MultiLanguages.GetString("tbl_Contract", "Subject", this.colSubject.Caption);
            this.colDescription.Caption = MultiLanguages.GetString("tbl_Contract", "Description", this.colDescription.Caption);
        }

        private void LoadGrid(int Level, string Code)
        {
            HRM_CONTRACT hrm_contract = new HRM_CONTRACT();
            if ((((Level == 0) || (Level == 1)) || (Level == 2)) || (Level == 3))
            {
                this.gcList.DataSource = hrm_contract.GetList(Level, Code);
            }
            else if (Level == 4)
            {
                this.gcList.DataSource = hrm_contract.GetListByEmployee(Code);
            }
        }

        private void LoadOrganization()
        {
            this.xucListContractEmployee1.LoadData(1);
            this.xucListContractEmployee1.EmployeeSelected += (s, e) => this.LoadGrid(this.m_Level = 4, this.m_Code = e);
            this.xucListContractEmployee1.DepartmentSelected += delegate (object s, Organization o) {
                HRM_GROUP hrm_group = new HRM_GROUP();
                HRM_DEPARTMENT hrm_department = new HRM_DEPARTMENT();
                HRM_BRANCH hrm_branch = new HRM_BRANCH();
                if (o.Level == 0)
                {
                    this.LoadGrid(this.m_Level = 0, this.m_Code = "");
                }
                else if (o.Level == 1)
                {
                    this.LoadGrid(this.m_Level = 1, this.m_Code = o.BranchCode);
                }
                else if (o.Level == 2)
                {
                    this.LoadGrid(this.m_Level = 2, this.m_Code = o.DepartmentCode);
                }
                else if (o.Level == 3)
                {
                    this.LoadGrid(this.m_Level = 3, this.m_Code = o.GroupCode);
                }
            };
        }

        private static int LoadStyle()
        {
            try
            {
                DataSet set = new DataSet();
                set.ReadXml(Application.StartupPath + @"\LayoutControl\xucContract.xml");
                return int.Parse(set.Tables[0].Rows[0][0].ToString());
            }
            catch
            {
                return 270;
            }
        }

        private void RaiseClosedHander()
        {
            if (this.Closed != null)
            {
                this.Closed(this);
            }
        }

        private void repFilter_EditValueChanged(object sender, EventArgs e)
        {
            HRM_CONTRACT hrm_contract;
            if (this.m_Filter == "0")
            {
                hrm_contract = new HRM_CONTRACT();
                this.gcList.DataSource = hrm_contract.GetList(this.m_Level, this.m_Code);
            }
            else if (this.m_Filter == "1")
            {
                hrm_contract = new HRM_CONTRACT();
                this.gcList.DataSource = hrm_contract.GetCurrentList(this.m_Level, this.m_Code);
            }
            else if (this.m_Filter == "2")
            {
                hrm_contract = new HRM_CONTRACT();
                this.gcList.DataSource = hrm_contract.GetListJustExpiration(this.m_Level, this.m_Code);
            }
            else
            {
                this.gcList.DataSource = new HRM_CONTRACT().GetListExpiration(this.m_Level, this.m_Code);
            }
        }

        private void repFilter_EditValueChanging(object sender, ChangingEventArgs e)
        {
            this.m_Filter = e.NewValue.ToString();
        }

        private static void SaveStyle(int Position)
        {
            DataSet set = new DataSet();
            using (DataTable table = new DataTable())
            {
                table.Columns.Add("SplitterPosition", typeof(string));
                object[] objArray = new object[] { Position.ToString() };
                table.Rows.Add(new object[0]);
                table.Rows[0][0] = objArray[0];
                set.Tables.Add(table);
            }
            try
            {
                set.WriteXml(Application.StartupPath + @"\LayoutControl\xucContract.xml");
            }
            catch
            {
            }
        }

        private void SetMenu(Common.Class.RowClickEventArgs e)
        {
            object rowCellValue = this.gbList.GetRowCellValue(this.gbList.FocusedRowHandle, "ContractCode");
            this.DisableMenu(false);
            if (rowCellValue == null)
            {
                this.DisableMenu(true);
            }
        }

        private void splitContainerControl1_SplitterPositionChanged(object sender, EventArgs e)
        {
            SaveStyle(this.splitContainerControl1.SplitterPosition);
        }

        private void ucList_ListKeyDown(object sender, KeyEventArgs key)
        {
            if (key.KeyCode == Keys.F2)
            {
                if (this.gbList.RowCount != 0)
                {
                    this.Change();
                }
            }
            else if ((key.KeyCode == Keys.Control) | (key.KeyCode == Keys.E))
            {
                if (this.gbList.RowCount != 0)
                {
                    this.Change();
                }
            }
            else if (key.KeyCode == Keys.Enter)
            {
                if (this.gbList.RowCount != 0)
                {
                    this.Change();
                }
            }
            else if (key.KeyCode == Keys.F5)
            {
                this.Init();
            }
            else if ((key.KeyCode == Keys.Control) | (key.KeyCode == Keys.N))
            {
                this.Add();
            }
            else if ((key.KeyCode == Keys.Control) | (key.KeyCode == Keys.T))
            {
                this.Add();
            }
        }

        private void UpdateRow(HRM_CONTRACT item)
        {
            GridView gbList = this.gbList;
            int focusedRowHandle = this.gbList.FocusedRowHandle;
            gbList.SetRowCellValue(focusedRowHandle, "ContractCode", item.ContractCode);
            gbList.SetRowCellValue(focusedRowHandle, "ContractType", item.ContractType);
            gbList.SetRowCellValue(focusedRowHandle, "ContractTime", item.ContractTime);
            gbList.SetRowCellValue(focusedRowHandle, "SignDate", item.SignDate);
            gbList.SetRowCellValue(focusedRowHandle, "FromDate", item.FromDate);
            gbList.SetRowCellValue(focusedRowHandle, "ToDate", item.ToDate);
            gbList.SetRowCellValue(focusedRowHandle, "Signer", item.Signer);
            gbList.SetRowCellValue(focusedRowHandle, "SignerPosition", item.SignerPosition);
            gbList.SetRowCellValue(focusedRowHandle, "Subject", item.Subject);
            gbList.SetRowCellValue(focusedRowHandle, "Description", item.Description);
            gbList.UpdateCurrentRow();
        }

        public delegate void ClosedHander(object sender);
    }
}

